<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">
        <div class="layui-form">

        <blockquote class="layui-elem-quote layui-text">
            请填写准确信息：着重写准日期（如发现有错误，请新建劳务合同，勿修改）
        </blockquote>

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>新建劳务合同</legend>
        </fieldset>

        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">合同编号</label>
                <div class="layui-input-block">
                    <input type="text" name="rsbConNum" lay-verify="required" lay-reqtext="合同编号不能为空" autocomplete="off" placeholder="请输入合同编号" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">合同名称</label>
                <div class="layui-input-block">
                    <input  name="rsbConName" lay-verify="required" lay-reqtext="合同名称不能为空" placeholder="请输入合同名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">合同类别</label>
                <div class="layui-input-block">
                    <select name="rsbConType">
                        <option value=""></option>
                        <option value="实习合同">实习合同</option>
                        <option value="转正合同">转正合同</option>
                        <option value="续签合同">续签合同</option>
                        <option value="保密协议">保密协议</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">员工编号</label>
                    <div class="layui-input-inline">
                        <input  name="userNum" lay-verify="required" lay-reqtext="员工编号不能为空" placeholder="请输入员工编号" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline">
                        <input  name="userName" lay-verify="required" lay-reqtext="员工姓名不能为空" placeholder="请输入员工姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">所属部门</label>
                    <div class="layui-input-inline">
                        <select name="rsbMonDep" lay-verify="required" lay-reqtext="部门不能为空" lay-filter="dep">
                            <option></option>
                            <option value="人事部">人事部</option>
                            <option value="销售部">销售部</option>
                            <option value="生产部">生产部</option>
                            <option value="财务部">财务部</option>
                            <option value="研发部">研发部</option>
                            <option value="物资部">物资部</option>
                            <option value="无">无</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">所属职位</label>
                    <div class="layui-input-inline">
                        <select name="rsbMonPost" id="rsbMonPost" lay-verify="required" lay-reqtext="职位不能为空" lay-filter="post">
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">签约时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rsbConNow" lay-verify="required" lay-reqtext="请输入签约时间" class="layui-input" id="test5" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">生效时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rsbConBegin" lay-verify="required" lay-reqtext="请输入生效时间" class="layui-input" id="test6" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">失效时间</label>
                    <div class="layui-input-inline">
                        <input type="text" name="rsbConEnd2" lay-verify="required" lay-reqtext="请输入失效时间" class="layui-input" id="test7" placeholder="yyyy-MM-dd HH:mm:ss">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">基本薪资</label>
                <div class="layui-input-block">
                    <input type="number" name="rsbConBasepay" lay-verify="required" lay-reqtext="基本薪资不能为空" autocomplete="off" placeholder="请输入基本薪资" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">附件上传</label>
                    <div class="layui-input-inline">
                        <input type="file" name="rsbConPath" class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">标注</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        //日期
        laydate.render({
            elem: '#test5'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test6'
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#test7'
            ,type: 'datetime'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            var datas=data.field;
            $.ajax({
                url:"/insertContract",
                method:'post',
                data: datas,
                dataType:"json",
                success:function(data){
                    console.log(data);
                    if(data.data==1){
                        alert("添加成功！");
                    }
                }
            })
        });

        //表单初始赋值
        form.val('example', {
            "username": "贤心" // "name": "value"
            , "password": "123456"
            , "interest": 1
            , "like[write]": true //复选框选中状态
            , "close": true //开关状态
            , "sex": "女"
            , "desc": "我爱 layui"
        })

        //部门职位select二级联动
        form.on('select(dep)',function(data){
            var url="/showPost?dep="+data.value;
            $.get(url,function (data) {
                var tmp='<option value="">请选择</option>';
                for (var i in data){
                    tmp +='<option value="'+data[i]+'">'+data[i]+'</option>';
                }
                $("#rsbMonPost").html(tmp);
                //重载select模块，否则不会展示
                layui.form.render("select");
            });
        })


    });
</script>